// Package base

// @Copyright  Copyright (c) 2023 HotGo CLI

package base

import (
	"context"
	"hotgo/api/home/base"
	"hotgo/internal/consts"
	"hotgo/internal/model"
	"hotgo/internal/service"
	"hotgo/utility/simple"

	"github.com/gogf/gf/v2/frame/g"
)

// Site 基础
var Site = cSite{}

type cSite struct{}

func (a *cSite) Index(ctx context.Context, _ *base.SiteIndexReq) (res *base.SiteIndexRes, err error) {
	service.View().RenderTpl(ctx, "index.html", model.View{Data: g.Map{
		"name":    simple.AppName(ctx),
		"version": consts.VersionApp,
	}})

	// err = gerror.New("这是一个测试错误")
	// return

	// err = gerror.NewCode(gcode.New(10000, "这是一个测试自定义错误码错误", nil))
	// return

	// service.View().Error(ctx, gerror.New("这是一个允许被自定义格式的错误，默认和通用错误格式一致，你可以修改它"))
	// return
	return
}

/**
 * @Description: 购买
 * @param ctx
 * @param req
 * @return res
 * @return err
 */
func (a *cSite) Buy(ctx context.Context, _ *base.SiteBuyReq) (res *base.SiteBuyRes, err error) {
	service.View().RenderTpl(ctx, "buy.html", model.View{Data: g.Map{
		"name":    simple.AppName(ctx),
		"version": consts.VersionApp,
	}})
	return
}

/**
 * @Description: 帮助
 * @param ctx
 * @param req
 * @return res
 * @return err
 */
func (a *cSite) Help(ctx context.Context, _ *base.SiteHelpReq) (res *base.SiteHelpRes, err error) {
	service.View().RenderTpl(ctx, "help.html", model.View{Data: g.Map{
		"name":    simple.AppName(ctx),
		"version": consts.VersionApp,
	}})
	return
}

/**
 * @Description: 出售
 * @param ctx
 * @param req
 * @return res
 * @return err
 */
func (a *cSite) Sell(ctx context.Context, _ *base.SiteSellReq) (res *base.SiteSellRes, err error) {
	service.View().RenderTpl(ctx, "sell.html", model.View{Data: g.Map{
		"name":    simple.AppName(ctx),
		"version": consts.VersionApp,
	}})
	return
}

/**
 * @Description: 交易记录
 * @param ctx
 * @param req
 * @return res
 * @return err
 */
func (a *cSite) Transaction(ctx context.Context, _ *base.SiteTransactionReq) (res *base.SiteTransactionRes, err error) {
	service.View().RenderTpl(ctx, "transaction.html", model.View{Data: g.Map{
		"name":    simple.AppName(ctx),
		"version": consts.VersionApp,
	}})
	return
}
